#!/bin/bash
set -e

# 配置GRUB默认启动实时内核
echo "配置GRUB默认启动实时内核..."
sed -i 's/GRUB_DEFAULT=0/GRUB_DEFAULT="Advanced options for Debian GNU\/Linux>Debian GNU\/Linux, with Linux 6.1.0-rt-amd64"/' /etc/default/grub
update-grub

# 配置EtherCAT主站
echo "配置EtherCAT主站..."
cat << EOF > /etc/ethercat.conf
MASTER0_DEVICE="eth0"
DEVICE_MODULES="generic"
EOF

# 创建系统服务
echo "创建系统服务..."
cat << EOF > /etc/systemd/system/robot_controller.service
[Unit]
Description=Industrial Robot Controller
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/robot_controller
Restart=always
RestartSec=1
LimitRTPRIO=99
LimitMEMLOCK=infinity

[Install]
WantedBy=multi-user.target
EOF

# 启用系统服务
systemctl daemon-reload
systemctl enable robot_controller

# 创建配置目录
mkdir -p /etc/robot_control/devices
mkdir -p /etc/robot_control/safety

echo "系统配置完成"
